//
//  SearchTableViewCell.m
//  CoJellyCartoon
//
//  Created by kingbw on 16/3/31.
//  Copyright © 2016年 CJG. All rights reserved.
//

#import "SearchTableViewCell.h"

@implementation SearchTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //视频大图
        self.imgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self addSubview:self.imgView];
        
        //标题
        self.title = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.title.numberOfLines = 2;
        self.title.font = [UIFont systemFontOfSize:15];
        [self addSubview:self.title];
        
        //up图标
        self.up = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.up.image = [UIImage imageNamed:@"upzhu"];
        [self addSubview:self.up];
        
        //up主名字
        self.upName = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.upName.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.upName];
        
        //播放图标
        self.play = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.play.image = [UIImage imageNamed:@"bofang"];
        [self addSubview:self.play];
        
        //播放数量
        self.playCount = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.playCount.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.playCount];
        
        //评论图标
        self.comment = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.comment.image = [UIImage imageNamed:@"pinglun"];
        [self addSubview:self.comment];
        
        //评论数量
        self.commentCount = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.commentCount.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.commentCount];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imgView.frame = CGRectMake(10, 10, ScreenWidth / 2.5, ScreenHeight / 6.5);
    self.title.frame = CGRectMake(self.imgView.frame.size.width + 15, 5, ScreenWidth / 2, self.imgView.frame.size.height / 2.1);
//    self.title.frame = CGRectMake(ScreenWidth*180.6/414, ScreenHeight*5/736, ScreenWidth*207/414, ScreenHeight*(ScreenHeight/6.5/2.1)/736);
    self.up.frame = CGRectMake(self.imgView.frame.size.width + 15, self.imgView.frame.size.height / 2.1 + 10, ScreenWidth*20/414, ScreenHeight*16/736);
    self.upName.frame = CGRectMake(self.imgView.frame.size.width + 45, self.imgView.frame.size.height / 2.2 + 10, ScreenWidth*200/414, ScreenHeight*20/736);
    self.play.frame = CGRectMake(self.imgView.frame.size.width + 15, self.imgView.frame.size.height - ScreenHeight*25/736, ScreenWidth*20/414, ScreenHeight*16/736);
    self.playCount.frame = CGRectMake(self.imgView.frame.size.width + 45, self.imgView.frame.size.height - ScreenHeight*25/736, ScreenWidth*60/414, ScreenHeight*20/736);
    self.comment.frame = CGRectMake(ScreenWidth * 300 / 414, self.imgView.frame.size.height - ScreenHeight*25/736, ScreenWidth*20/414, ScreenHeight*16/736);
    self.commentCount.frame = CGRectMake(ScreenWidth * 330 / 414, self.imgView.frame.size.height - ScreenHeight*25/736, ScreenWidth * 50 / 414, ScreenHeight * 20 / 736);
    
}

- (void)setSearchModel:(SearchModel *)searchModel {
    _searchModel = searchModel;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:searchModel.pic] placeholderImage:[UIImage imageNamed:@"zhanweiye"]];
    self.title.text = searchModel.title;
    self.upName.text = searchModel.author;
    
    self.playCount.text = [NSString stringWithFormat:@"%@", searchModel.play.floatValue > 10000 ? [NSString stringWithFormat:@"%0.1f万", (searchModel.play.floatValue / 10000.0)] : searchModel.play];
    
    self.commentCount.text = [NSString stringWithFormat:@"%@", searchModel.video_review.floatValue > 10000 ? [NSString stringWithFormat:@"%0.1f万", (searchModel.video_review.floatValue / 10000.0)]:searchModel.video_review];
    
}


@end
